﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAzure.StorageClient;

namespace WadViewer.DomainModel
{
	/// <summary>
	/// Entity with properties that are stored in all WAD tables
	/// </summary>
	public abstract class WadEntity : TableServiceEntity
	{
		/// <summary>
		/// Identification of the deployment
		/// </summary>
		public string DeploymentId { get; set; }

		/// <summary>
		/// Name of the role
		/// </summary>
		public string Role { get; set; }

		/// <summary>
		/// Name of the role instance
		/// </summary>
		public string RoleInstance { get; set; }

		/// <summary>
		/// What to display in a list of entities
		/// </summary>
		public abstract string ListDisplay { get; }

		/// <summary>
		/// ToString overrides
		/// </summary>
		/// <returns></returns>
		public override string ToString()
		{
			return string.Format("{0}\t{1}\t{2}\t{3}", Timestamp, DeploymentId, Role, RoleInstance);
		}

		/// <summary>
		/// Reduces the number of lines to three
		/// </summary>
		/// <param name="source">source string</param>
		/// <returns></returns>
		protected string MaxThreeLines(string source)
		{
			string[] allLines = source.Split('\n');
			StringBuilder builder = new StringBuilder();
			int count;
			for (count = 0; (count < allLines.Length) && (count < 3); count++)
			{
				builder.Append(allLines[count]);
				if(count < allLines.Length-1) builder.AppendLine();
			}
			if (count < allLines.Length)
			{
				builder.Append(".....");
			}
			return builder.ToString();
		}
	}
}
